package com.example.ticket.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.ticket.entity.Ticket;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TicketMapper extends BaseMapper<Ticket> {
    //票据列表
    @Select("SELECT * FROM `t_ticket` where status!='0'")
    public List<Ticket> TicketList();

    //票据ID修改票据状态
    @Update("update t_ticket set status=#{status} where id=#{id}")
    public int updateTicketStatus(Integer status,Integer id);

    //退回原因
    @Update("update t_ticket set status=#{status},remark=#{remark} where id=#{id}")
    public int updateBack(Ticket ticket);


    //添加票据(保存)
    @Insert("insert into t_ticket" +
            "(companyName,money,subject,body,type,status,user_id,remark) " +
            "values" +
            "(#{companyName},#{money},#{subject},#{body},#{type},#{status},#{userId},#{remark})")
    public int insertTicket(Ticket ticket);
/*    public int insertTicket(String companyName,Double money,String subject,String body,
                            String type,Integer status,Integer userId,String remark);*/

    //票据ID删除票据
    @Delete("delete from t_ticket where id=#{id}")
    public int deleteById(Integer id);

    //票据ID看票据详情
    @Select("select * from t_ticket where id=#{id}")
    public Ticket selectById(Integer id);


    //票据ID修改票据信息
    @Update("update t_ticket set companyName=#{companyName},money=#{money},subject=#{subject}" +
            ",body=#{body},type=#{type},status=#{status},submitdate=#{submitdate} where id=#{id}")
    public Integer updateTicketById(Ticket ticket);

    //查看自己所有的票据
    @Select("select * from t_ticket where user_id=#{userId}")
    public List<Ticket> selectMyTicket(Integer userId);


    //根据状态查询自己的票据
    @Select("select * from t_ticket where user_id=#{userId} and status=#{status}")
    public List<Ticket> selectMyTicketByStatus(Integer userId,Integer status);

    //查看所有未审核的票据
    @Select("select * from t_ticket where status=#{status}")
    public List<Ticket> selectSTticket(Integer status);


/*
    //模糊查找票据自己的票据
    @Select("select * from t_ticket where companyName like concat('%',#{companyName},'%') and user_id=#{id}")
    public List<Ticket> selectBycondition(String companyName,Integer id);
*/

    //多条件查询
    public List<Ticket> selectALLBycondition(Ticket ticket);

    //多条件查询个人票据
    public List<Ticket> selectMyBycondition(Ticket ticket);


    //动态修改票据
    public Integer ChangeTicket(Ticket ticket);
}
